﻿Imports System
Imports System.CodeDom
Imports System.Collections
Imports System.Collections.Generic

Namespace System.Workflow.Activities.Rules
    Friend Class OverloadedTypeSymbol
        Inherits TypeSymbolBase
        ' Methods
        Private Sub New(ByVal name As String, ByVal typeSymbols As List([Of] TypeSymbol))
            Me.TypeSymbols = New List([Of] TypeSymbol)
            Me.name = name
            Me.TypeSymbols = typeSymbols
        End Sub

        Friend Sub New(ByVal name As String, ByVal typeSym1 As TypeSymbol, ByVal typeSym2 As TypeSymbol)
            Me.TypeSymbols = New List([Of] TypeSymbol)
            Me.name = name
            Me.AddLocalType(typeSym1)
            Me.AddLocalType(typeSym2)
        End Sub

        Friend Sub AddLocalType(ByVal typeSym As TypeSymbol)
            Me.TypeSymbols.Add(typeSym)
        End Sub

        Friend Overrides Function OverloadType(ByVal newTypeSymBase As TypeSymbolBase) As OverloadedTypeSymbol
            Dim typeSymbols As New List([Of] TypeSymbol)
            Dim item As TypeSymbol = Nothing
            Dim symbol2 As OverloadedTypeSymbol = [TryCast](newTypeSymBase,OverloadedTypeSymbol)
            If (Not symbol2 Is Nothing) Then
                typeSymbols.AddRange(symbol2.TypeSymbols)
            Else
                item = [TryCast](newTypeSymBase,TypeSymbol)
                If (Not item Is Nothing) Then
                    typeSymbols.Add(item)
                End If
            End If
            Dim symbol3 As TypeSymbol
            For Each symbol3 In Me.TypeSymbols
                Dim symbol4 As TypeSymbol
                For Each symbol4 In typeSymbols
                    If Not symbol4.CanOverload(symbol3) Then
                        Return Nothing
                    End If
                Next
                typeSymbols.Add(symbol3)
            Next
            Return New OverloadedTypeSymbol(Me.name, typeSymbols)
        End Function

        Friend Overrides Function ParseRootIdentifier(ByVal parser As Parser, ByVal parserContext As ParserContext, ByVal assignIsEquality As Boolean) As CodeExpression
            Return parser.ParseRootOverloadedTypeIdentifier(parserContext, Me.TypeSymbols, assignIsEquality)
        End Function

        Friend Overrides Sub RecordSymbol(ByVal list As ArrayList)
            Dim symbol As TypeSymbol
            For Each symbol In Me.TypeSymbols
                list.Add(symbol.Type)
            Next
        End Sub


        ' Properties
        Friend Overrides ReadOnly Property Name As String
            Get
                Return Me.name
            End Get
        End Property


        ' Fields
        Private name As String
        Friend TypeSymbols As List([Of] TypeSymbol)
    End Class
End Namespace

